package com.example.smart.ui.m

import com.example.lib.extend.setOnDoubleClickListener
import com.example.lib.utils.sp.SpUtils
import com.example.lib.utils.statusbar.StatusBarUtils
import com.example.smart.R
import com.example.smart.base.ui.activity.BaseActivity
import com.example.smart.databinding.ActivityToadyCircleMBinding
import com.example.smart.utils.DisplayUtils

class MTodayCircleActivity : BaseActivity<ActivityToadyCircleMBinding>() {
    private var flag1 = SpUtils.getBoolean("post1", false)
    private var flag2 = SpUtils.getBoolean("post2", false)

    private var flag3 = SpUtils.getBoolean("gz1", false)
    private var flag4 = SpUtils.getBoolean("gz2", false)
    override fun layoutID() = R.layout.activity_toady_circle_m

    override fun initView() {
        StatusBarUtils.setStateAndNavigationBar(this@MTodayCircleActivity,
            statusBarColor = com.example.lib.R.color.translate)

        if (flag1) {
            binding.LikeImage.setImageResource(R.mipmap.icon_like2_on)
            binding.LikeText.text = "125"
        } else {
            binding.LikeImage.setImageResource(R.mipmap.icon_like2)
            binding.LikeText.text = "124"
        }

        if (flag2) {
            binding.LikeImage2.setImageResource(R.mipmap.icon_like2_on)
            binding.LikeText2.text = "125"
        } else {
            binding.LikeImage2.setImageResource(R.mipmap.icon_like2)
            binding.LikeText2.text = "124"
        }
    }

    override fun onResume() {
        super.onResume()
        flag3 = SpUtils.getBoolean("gz1", false)
        flag4 = SpUtils.getBoolean("gz2", false)
        if (flag3) {
            binding.Text3.text = "已关注"
        } else {
            binding.Text3.text = "关注"
        }

        if (flag4) {
            binding.Text9.text = "已关注"
        } else {
            binding.Text9.text = "关注"
        }
    }

    override fun initListener() {
        binding.LikeLayout.setOnDoubleClickListener {
            flag1 = !flag1
            SpUtils.putBoolean("post1", flag1)
            if (flag1) {
                binding.LikeImage.setImageResource(R.mipmap.icon_like2_on)
                binding.LikeText.text = "125"
            } else {
                binding.LikeImage.setImageResource(R.mipmap.icon_like2)
                binding.LikeText.text = "124"
            }
        }

        binding.LikeLayout2.setOnDoubleClickListener {
            flag2 = !flag2
            SpUtils.putBoolean("post2", flag2)
            if (flag2) {
                binding.LikeImage2.setImageResource(R.mipmap.icon_like2_on)
                binding.LikeText2.text = "125"
            } else {
                binding.LikeImage2.setImageResource(R.mipmap.icon_like2)
                binding.LikeText2.text = "124"
            }
        }

        binding.Text3.setOnDoubleClickListener {
            flag3 = !flag3
            SpUtils.putBoolean("gz1", flag3)
            if (flag3) {
                binding.Text3.text = "已关注"
            } else {
                binding.Text3.text = "关注"
            }
        }

        binding.Text9.setOnDoubleClickListener {
            flag4 = !flag4
            SpUtils.putBoolean("gz2", flag4)
            if (flag4) {
                binding.Text9.text = "已关注"
            } else {
                binding.Text9.text = "关注"
            }
        }

        binding.Search.setOnDoubleClickListener {
            DisplayUtils.toSearch(this@MTodayCircleActivity)
        }

        binding.Layout1.setOnDoubleClickListener {
            DisplayUtils.toCommunityDetails(this@MTodayCircleActivity, 1)
        }

        binding.Layout2.setOnDoubleClickListener {
            DisplayUtils.toCommunityDetails(this@MTodayCircleActivity, 2)
        }

        binding.Post.setOnDoubleClickListener {
            DisplayUtils.toPost(this@MTodayCircleActivity)
        }
    }

    override fun isNeedAllTab() = true
}